package com.achilles.widget;

import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.achilles.bean.DataBean;
import com.achilles.callback.IProjectOrGiftDialogItemClick;
import com.achilles.playtask.R;

/**
 * Created by AchillesL on 2016-9-22.
 */
public class ProjectOrGiftItemDialog {

    private AlertDialog mAlertDialog;
    private IProjectOrGiftDialogItemClick mIProjectOrGiftDialogItemClick;
    private DataBean mClickDataBean;

    public ProjectOrGiftItemDialog(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.project_gift_dialog_layout,null);
        TextView tvEdit = (TextView) view.findViewById(R.id.tvEdit);
        TextView tvDelete = (TextView) view.findViewById(R.id.tvDelete);
        tvEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mIProjectOrGiftDialogItemClick != null) {
                    mIProjectOrGiftDialogItemClick.onEditClick(mClickDataBean);
                }
                mAlertDialog.dismiss();
            }
        });
        tvDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mIProjectOrGiftDialogItemClick != null) {
                    mIProjectOrGiftDialogItemClick.onDeleteClick(mClickDataBean);
                }
                mAlertDialog.dismiss();
            }
        });

        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setView(view);
        mAlertDialog = builder.create();
    }

    public void setIProjectOrGiftDialogItemClick(IProjectOrGiftDialogItemClick IProjectOrGiftDialogItemClick) {
        this.mIProjectOrGiftDialogItemClick = IProjectOrGiftDialogItemClick;
    }

    public void show() {
        mAlertDialog.show();
    }

    public void setClickDataBean(DataBean dataBean) {
        this.mClickDataBean = dataBean;
    }
}
